package com.gxc.slidingWindow;

import java.util.HashSet;
import java.util.Set;

/**
 * 给定一个字符串 s ，请你找出其中不含有重复字符的 最长 子串 的长度。
 */
public class LengthOfLongestSubstring {

    public int lengthOfLongestSubstring(String s) {
        int left = 0, right = 0;
        int res = 0;
        Set<Character> set = new HashSet<>();
        while (right < s.length()) {
            char c = s.charAt(right);
            while (set.contains(c)) {
                set.remove(s.charAt(left));
                left++;
            }
            set.add(c);
            right++;
            res = Math.max(res, set.size());
        }
        return res;
    }
}
